package com.qingpeng.pay.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.qingpeng.pay.R;
import com.qingpeng.pay.adapter.MoneyAdapter;
import com.qingpeng.pay.adapter.QRCodelistAdapter;
import com.qingpeng.pay.api.Host;
import com.qingpeng.pay.api.RedBag;
import com.qingpeng.pay.base.BaseActivity;
import com.qingpeng.pay.beans.QRCodeListBean;
import com.qingpeng.pay.beans.WithdrawBean;
import com.qingpeng.pay.okhttp.RetrofitCreateHelper;
import com.qingpeng.pay.utils.ToastUtils;
import com.qingpeng.pay.views.TitleBar;

import java.util.List;

import butterknife.BindView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MoneyListActivity extends BaseActivity {


    @BindView(R.id.title)
    TitleBar title;
    private List<WithdrawBean.DataProductBean> mData;

    private String mType;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_money_list;
    }

    @Override
    protected int getRootViewId() {
        return 0;
    }

    @Override
    protected int getRefreshId() {
        return 0;
    }

    @Override
    protected int getListViewId() {
        return R.id.recycler;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        mType = getIntent().getStringExtra("type");
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onResume() {
        super.onResume();
        title.getLlLeft().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        if (mType.equals("2")) {
            title.setTitle("提现记录");
            Call<WithdrawBean> getwithdrawlist = RetrofitCreateHelper.createApi(RedBag.class, Host.HOST).getwithdrawlist();
            getwithdrawlist.enqueue(new Callback<WithdrawBean>() {
                @Override
                public void onResponse(Call<WithdrawBean> call, Response<WithdrawBean> response) {
                    WithdrawBean body = response.body();
                    if (body.getStatus() != 1) {
                        ToastUtils.showToast(MoneyListActivity.this, body.getInfo());
                        return;
                    }
                    mData = body.getData();
                    initAdapter();
                }

                @Override
                public void onFailure(Call<WithdrawBean> call, Throwable t) {
                    ToastUtils.showToast(MoneyListActivity.this, "网络请求错误,请稍后重试");
                }
            });
        } else {
            title.setTitle("充值记录");
            Call<WithdrawBean> getwithdrawlist = RetrofitCreateHelper.createApi(RedBag.class, Host.HOST).getrechargelist();
            getwithdrawlist.enqueue(new Callback<WithdrawBean>() {
                @Override
                public void onResponse(Call<WithdrawBean> call, Response<WithdrawBean> response) {
                    WithdrawBean body = response.body();
                    if (body.getStatus() != 1) {
                        ToastUtils.showToast(MoneyListActivity.this, body.getInfo());
                        return;
                    }
                    mData = body.getData();
                    initAdapter();
                }

                @Override
                public void onFailure(Call<WithdrawBean> call, Throwable t) {
                    ToastUtils.showToast(MoneyListActivity.this, "网络请求错误,请稍后重试");
                }
            });
        }

    }

    @Override
    protected void initAdapter() {
        mAdapter = new MoneyAdapter(R.layout.item_money_list);
        mAdapter.setNewData(mData);
        super.initAdapter();
    }
}
